package no.cicero.testframework.xml.testcase;

import no.cicero.testframework.common.xml.XmlImporter;
import no.cicero.testframework.common.xml.XmlTag;
import no.cicero.testframework.model.testcase.StepParametersBase;
import no.cicero.testframework.xml.IXmlNameTable;


public abstract class StepParametersImporterHelper implements IXmlNameTable.IStepParameters {
    public static boolean handleText(XmlImporter importer, XmlTag tag, String text, StepParametersBase target) {
        if(tag.getName().equalsIgnoreCase(DESCRIPTION_ELEMENT)){
            target.setDescription(text);
        } else if(tag.getName().equalsIgnoreCase(WEBSERVICE_ELEMENT)){
            target.setWebservice(text);
        } else if(tag.getName().equalsIgnoreCase(METHOD_ELEMENT)){
            target.setMethod(text);
        } else if(tag.getName().equalsIgnoreCase(PRECISION_ELEMENT)){
            target.setPrecision(Double.parseDouble(text));
        } else
            return false;
        
        return true;
    }

    public static boolean handleStartElement(XmlImporter importer, XmlTag tag, StepParametersBase target) {
        if (tag.getName().equalsIgnoreCase(HEADER_PARAMS_PARAM_ELEMENT) && tag.getParent().getName().equalsIgnoreCase(HEADER_PARAMS_ELEMENT)) {
            String name = tag.getAttributes().getValue(HEADER_PARAMS_PARAM_NAME_ATTRIBUTE);
            String value = tag.getAttributes().getValue(HEADER_PARAMS_PARAM_VALUE_ATTRIBUTE);
            target.setParameter(name, value);
            return true;
        }
        return false;
    }

}
